import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { getAllRoleList, getDeptList, getDistrictCascader } from '/@/api/demo/system';

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '编号',
      dataIndex: 'fwbh',
      slots: { customRender: 'renderHouse' },
    },
  ];
}

export const searchDistrictFormSchema: FormSchema[] = [
  {
    field: 'districts_',
    label: '行政区划',
    component: 'ApiCascader',
    labelWidth: '10em',
    componentProps: ({ formModel, formActionType }) => {
      return {
        api: getDistrictCascader,
        apiParamKey: 'parentId',
        labelField: 'regionName',
        valueField: '_d',
        dataField: 'regionCode',
        asyncFetchParamKey: 'parentId',
        multiple: true,
        initFetchParams: {
          parentId: '',
        },
        isLeaf: (record) => {
          return record.regionalLevel > 6;
        },
      };
    },
  },
];

export const searchFormSchema: FormSchema[] = searchDistrictFormSchema.concat([
  {
    field: 'text',
    label: '地址',
    component: 'Input',
    labelWidth: '10em',
  },
  {
    field: 'fwbh',
    label: '房屋编号',
    component: 'Input',
    labelWidth: '10em',
  },
]);
// 消防--隐患排查--场所安全排查-- 搜索 下拉框
export function getSearchFormSchema(underMode: Array<String>) {
  let rets: FormSchema[] = Array<FormSchema>().concat(searchFormSchema);
  if (underMode?.includes('fire')) {
    rets = rets.concat([
      {
        field: 'pc_status',
        label: '排查状态',
        component: 'Select',
        componentProps: {
          options: [
            { label: '已排查', value: 1 },
            { label: '已排查无隐患', value: 20 },
            { label: '已排查有隐患', value: 21 },
            { label: '未排查', value: 0 },
          ],
          placeholder: '请选择排查状态',
        },
        labelWidth: '10em',
      },
      {
        field: 'buildingStorey',
        label: '建筑层数>',
        component: 'InputNumber',
        componentProps: {
          addonAfter: '层',
        },
        labelWidth: '10em',
      },
      {
        field: 'rentNum',
        label: '出租房间数>',
        component: 'InputNumber',
        componentProps: {
          addonAfter: '间',
        },
        labelWidth: '10em',
      },
      {
        field: 'rentPeople',
        label: '出租房间居住人数>',
        component: 'InputNumber',
        componentProps: {
          addonAfter: '人',
        },
        labelWidth: '10em',
      },
      {
        field: 'evaStairs',
        label: '疏散楼梯少于',
        component: 'InputNumber',
        componentProps: {
          addonAfter: '部',
        },
        labelWidth: '10em',
      },
    ]);
  }

  if (underMode?.includes('police')) {
    rets = rets.concat([
      {
        field: 'pcztPolice',
        label: underMode.length > 1 ? '公安排查状态' : '排查状态',
        component: 'Select',
        // 公安--隐患排查--城乡结合部重点村综合整治排查-- 搜索 下拉框
        componentProps: {
          options: [
            { label: '无需排查', value: 3 },
            // { label: '已排查', value: 2 },
            { label: '已排查无隐患', value: 20 },
            { label: '已排查有隐患', value: 21 },
            { label: '排查中', value: 1 },
            { label: '未排查', value: 0 },
          ],
          placeholder: '请选择排查状态',
        },
        labelWidth: '10em',
      },
      {
        field: 'placeTypeGa',
        label: '场所类型',
        component: 'Select',
        componentProps: {
          options: [
            { label: '居民', value: 0 },
            { label: '商业', value: 1 },
          ],
          placeholder: '请选择场所类型',
        },
        labelWidth: '10em',
      },
      {
        field: 'gaResidentFilter',
        label: '隐患选项',
        show: ({ schema, values, model, field }) => 0 == values['placeTypeGa'],
        component: 'Select',
        labelWidth: '10em',
        componentProps: {
          options: [
            {
              label: '未按要求落实租住人员登记',
              value: '{"checked":true,"code":"","title":"未按要求落实租住人员登记"}',
            },
            {
              label: '门窗缺少防盗锁具',
              value: '{"checked":true,"code":"","title":"门窗缺少防盗锁具"}',
            },
            {
              label: '缺少必要的监控设施',
              value: '{"checked":true,"code":"","title":"缺少必要的监控设施"}',
            },
            {
              label: '群租日租',
              value: '{"checked":true,"code":"","title":"群租日租"}',
            },
            {
              label: '现存违法犯罪窝点',
              value: '{"checked":true,"code":"","title":"现存违法犯罪窝点"}',
            },
            {
              label: '违法滋事风险人员居住',
              value: '{"checked":true,"code":"","title":"违法滋事风险人员居住"}',
            },
          ],
          placeholder: '请选择排查状态',
          mode: 'multiple',
        },
      },
      {
        field: 'gaCommercialFilter',
        label: '隐患选项',
        component: 'Select',
        labelWidth: '10em',
        show: ({ schema, values, model, field }) => 1 == values['placeTypeGa'],
        componentProps: {
          options: [
            {
              label: '无照经营旅馆等特种行业',
              value: '{"checked":true,"code":"","title":"无照经营旅馆等特种行业"}',
            },
            {
              label: '门窗缺少防盗锁具',
              value: '{"checked":true,"code":"","title":"门窗缺少防盗锁具"}',
            },
            {
              label: '缺少必要的监控设施',
              value: '{"checked":true,"code":"","title":"缺少必要的监控设施"}',
            },
            {
              label: '现存违法犯罪窝点',
              value: '{"checked":true,"code":"","title":"现存违法犯罪窝点"}',
            },
            {
              label: '违法滋事风险人员居住',
              value: '{"checked":true,"code":"","title":"违法滋事风险人员居住"}',
            },
          ],
          placeholder: '请选择排查状态',
          mode: 'multiple',
        },
      },
    ]);
  }

  if (underMode?.includes('housing')) {
    rets = rets.concat([
      {
        field: 'pcztHousing',
        label: underMode.length > 1 ? '房屋排查状态' : '排查状态',
        component: 'Select',
        componentProps: {
          options: [
            { label: '无需排查', value: 3 },
            { label: '已排查', value: 2 },
            { label: '排查中', value: 1 },
            { label: '未排查', value: 0 },
          ],
          placeholder: '请选择排查状态',
        },
        labelWidth: '10em',
      },
    ]);
  }

  return rets;
}
// 阳台的查询条件
export function getBalconyFormSchema(): any[] {
  return [
    {
      field: 'districts_',
      label: '行政区',
      component: 'ApiCascader',
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
      componentProps: ({ formModel, formActionType }) => {
        return {
          api: getDistrictCascader,
          apiParamKey: 'parentId',
          labelField: 'regionName',
          valueField: '_d',
          dataField: 'regionCode',
          asyncFetchParamKey: 'parentId',
          multiple: true,
          initFetchParams: {
            parentId: '',
          },
          isLeaf: (record) => {
            return record.regionalLevel > 6;
          },
        };
      },
    },
    {
      field: 'Text',
      label: '地址',
      defaultValue: null,
      component: 'Input',
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'build_no',
      label: '房屋编号',
      component: 'Input',
      defaultValue: null,
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'pczt',
      label: '楼栋排查状态',
      component: 'Select',
      // defaultValue: 9,
      componentProps: {
        options: [
          { label: '无需排查', value: 3 },
          { label: '已排查', value: 2 },
          { label: '排查中', value: 1 },
          { label: '未排查', value: 0 },
        ],
        placeholder: '请选择排查状态',
      },
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'sfljxjgz',
      label: '是否老旧小区改造',
      component: 'Select',
      // defaultValue: 9,
      componentProps: {
        options: [
          { label: '是', value: 1 },
          { label: '否', value: 0 },
        ],
        placeholder: '请选择老旧小区改造',
      },
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'build_site',
      label: '楼坐落',
      component: 'Input',
      defaultValue: null,
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'build_name',
      label: '楼名称',
      component: 'Input',
      defaultValue: null,
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'ownername',
      label: '产权人',
      component: 'Input',
      defaultValue: null,
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
    {
      field: 'jcnd',
      label: '建成年份',
      component: 'Input',
      defaultValue: null,
      labelWidth: '10em',
      colProps: { span: 12, flex: 1 },
    },
  ];
}

export function getBasicShortColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      width: 150,
      dataIndex: 'id',
      sorter: true,
      sortOrder: 'ascend',
    },
  ];
}

export function getMultipleHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
  ];
}

export function getCustomHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 200,
    },
  ];
}
const renderContent = ({ text, index }: { text: any; index: number }) => {
  const obj: any = {
    children: text,
    attrs: {},
  };
  if (index === 9) {
    obj.attrs.colSpan = 0;
  }
  return obj;
};
export function getMergeHeaderColumns(): BasicColumn[] {
  return [
    {
      title: 'ID',
      dataIndex: 'id',
      width: 300,
      customRender: renderContent,
    },
  ];
}
export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  const arr: any = [];
  for (let index = 0; index < itemNumber; index++) {
    arr.push({
      field: `field${index}`,
      label: `字段${index}`,
      component: 'Input',
      colProps: {
        xl: 12,
        xxl: 8,
      },
    });
  }
  return arr;
};
export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      ...getAdvanceSchema(5),
      {
        field: `field11`,
        label: `Slot示例`,
        component: 'Select',
        slot: 'custom',
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}
export function getBasicData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
      });
    }
    return arr;
  })();
  return data;
}

export function getTreeTableData() {
  const data: any = (() => {
    const arr: any = [];
    for (let index = 0; index < 40; index++) {
      arr.push({
        id: `${index}`,
        name: 'John Brown',
        age: `1${index}`,
        no: `${index + 10}`,
        address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
        beginTime: new Date().toLocaleString(),
        endTime: new Date().toLocaleString(),
        children: [
          {
            id: `l2-${index}`,
            name: 'John Brown',
            age: `1${index}`,
            no: `${index + 10}`,
            address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
            beginTime: new Date().toLocaleString(),
            endTime: new Date().toLocaleString(),
          },
        ],
      });
    }
    return arr;
  })();

  return data;
}
